using System;
using System.Globalization;

namespace jSLCore.Client.Presentation.jBinding.BaseConverters
{
    public class jIsToStringEquals : jChainConverter
    {
        public object EqualsTo{
            get;
            set;}

        public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == EqualsTo) return true;
            if(value==null || EqualsTo==null) return string.IsNullOrEmpty(value as string) == string.IsNullOrEmpty(EqualsTo as string);//not transparent, but good for jobs

            var resit = value.ToString()==EqualsTo.ToString();
            return resit;
        }

        public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if ((bool)value) return value.ToString();
            else return null;
        }
    }
}